package com.njtech.smartuniversity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njtech.smartuniversity.bean.CaseBean;
import com.njtech.smartuniversity.bean.CaseBeanExample;
import com.njtech.smartuniversity.dao.CaseBeanMapper;
import com.njtech.smartuniversity.service.CaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ritchie on 6/25/18
 */

@Service
public class CaseServiceImpl implements CaseService {

    @Autowired
    public CaseBeanMapper mCaseBeanMapper;

    @Override
    public CaseBean select(int id) {

        return  mCaseBeanMapper.select(id);
    }

    @Override
    public int update(CaseBean areaBean) {
        Integer id = areaBean.getId();
        return  mCaseBeanMapper.update(areaBean);
    }

    @Override
    public List<CaseBean> getAllCase(int area_id) {
        CaseBeanExample caseBeanExample = new CaseBeanExample();
        CaseBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        if (area_id!=5){
        criteria.andSIUuidEqualTo(area_id);
        }
        return mCaseBeanMapper.selectByExample(caseBeanExample);
    }

    @Override
    public PageInfo<CaseBean> getCasesByPage(int pageNum, int pageSize,int area_id) {
        PageHelper.startPage(pageNum, pageSize);
        List<CaseBean> list = getAllCase(area_id);//这个查询会分页
        return new PageInfo<>(list);
    }


    @Override
    public boolean deleteById(int id) {
        int result = mCaseBeanMapper.delete(id);
        return result != 0;
    }

    @Override
    public int addCase(CaseBean caseBean) {
        return mCaseBeanMapper.insert(caseBean);
    }
    @Override
    public int casenumber( int area)
    {
        CaseBeanExample caseBeanExample = new CaseBeanExample();
        CaseBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        if (area!=5){
            criteria.andSIUuidEqualTo(area);
        }
        return mCaseBeanMapper.countByExample(caseBeanExample);
    }


}
